<?php
require_once("database.php");
class xl_loai_bai_viet extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from loai_bai_viet limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	
	function danh_sach_all()
	{
		$sql = "select * from loai_bai_viet";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	
	function so_luong()
	{
		$sql = "select count(*) from loai_bai_viet";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	
	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from loai_bai_viet where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	
	function kiem_tra_co_con($ma)
	{
		$ma = intval($ma);

		$sql = "select * from loai_bai_viet where ma_loai_cha = '$ma'";
		$this->setQuery($sql);
		$row = $this->loadRow();
		
		if($row != NULL) 
			return true;
		else
			return false;
		
	}	
	
	function xem_ten_loai_cha($ma)
	{
		$ma = intval($ma);

		$sql = "select ten from loai_bai_viet where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	
	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from loai_bai_viet where ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	
	function them($ten, $mo_ta, $ma_loai_cha, $thu_tu_hien_thi)
	{
		$ten = stripslashes($ten);
		$ten = addslashes($ten);
		$mo_ta = stripslashes($mo_ta);
		$mo_ta = addslashes($mo_ta);
		$ma_loai_cha = intval($ma_loai_cha);
		$thu_tu_hien_thi = intval($thu_tu_hien_thi);

		$sql = "INSERT INTO loai_bai_viet(ten,mo_ta,ma_loai_cha,thu_tu_hien_thi) VALUES ('$ten','$mo_ta','$ma_loai_cha','$thu_tu_hien_thi')";
		$this->setQuery($sql);
		return $this->query();
	}
	
	function cap_nhat($ma, $ten, $mo_ta, $ma_loai_cha, $thu_tu_hien_thi)
	{
		$ma = intval($ma);
		$ten = stripslashes($ten);
		$ten = addslashes($ten);
		$mo_ta = stripslashes($mo_ta);
		$mo_ta = addslashes($mo_ta);
		$ma_loai_cha = intval($ma_loai_cha);
		$thu_tu_hien_thi = intval($thu_tu_hien_thi);

		$sql ="UPDATE loai_bai_viet SET ten= '$ten', mo_ta= '$mo_ta', ma_loai_cha= '$ma_loai_cha', thu_tu_hien_thi= '$thu_tu_hien_thi' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	
	function tim_kiem ($tu_khoa)
	{
		$sql = "select * from loai_bai_viet where	$ten like %tu_khoa% or 	$mo_ta like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>